define(function(require,exports,module) {
	// var muiPlug_url = './plug/mui/';
	require('./plug/mui/mui');

	var oHostList_TeShi = $('.js_hostList_TeShi');			//热门搜索

	// var myDate = {
	// 	"row" : [
	// 		{
	// 			"group" : 'A',
	// 			"cityNameInfo" : [
	// 				{
	// 					"cityName" : "阿克苏机场",
	// 					"tags" : "AKeSu"
	// 				},
	// 				{
	// 					"cityName" : "阿拉山口机场",
	// 					"tags" : "ALaShanKou"
	// 				}
	// 			]
	// 		},
	// 		{
	// 			"group" : 'B',
	// 			"cityNameInfo" : [
	// 				{
	// 					"cityName" : "保山机场",
	// 					"tags" : "BaoShan"
	// 				},
	// 				{
	// 					"cityName" : "包头机场",
	// 					"tags" : "BaoTou"
	// 				}
    //
	// 			]
	// 		},
    //
	// 		{
	// 			"group" : 'C',
	// 			"cityNameInfo" : [
	// 				{
	// 					"cityName" : "长白山机场",
	// 					"tags" : "ChangBaiShan"
	// 				},
	// 				{
	// 					"cityName" : "长春龙嘉国际机场",
	// 					"tags" : "ChangChunLongJiaGuoJi"
	// 				},
	// 				{
	// 					"cityName" : "常德桃花源机场",
	// 					"tags" : "ChangDeTaoHuaYuan"
	// 				}
	// 			]
	// 		}
	// 	]
    //
	// }


	var myDate;
	$.ajax({
		url: "/regionFeature/getCityData",
		type: "POST",
		data: null,
		dataType:'json',
		async:false,
		success:function (data) {
			if(data==undefined || data.length<1){
				return;
			}
			myDate = data;
		}

	});

	// console.log(JSON.stringify(myDate));



	var oCityListUl = $('.js_cityListUl');
	var oListBar = $('.js_listBar');

	require.async([ muiPlug_url+'mui.indexedlist'], function() {
		mui.init();
		mui.ready(function() {

			var oSearchBox = document.querySelector('.js_searchBox');
			var oHostList = document.querySelector('.js_hostList_TeShi');
			var list = document.getElementById('list');

			setGroup(myDate.row,function() {
				//calc hieght
				list.style.height = (document.body.offsetHeight - oSearchBox.offsetHeight - oHostList.offsetHeight)  + 'px';
				//create
				window.indexedList = new mui.IndexedList(list);
			})

			//热门城市点击
			mui('.js_hostList_TeShi').on('tap','li',function(e) {
				var index = $(this).index();
				oHostList_TeShi.find('li').removeClass('active').eq(index).addClass('active')
				console.log(oHostList_TeShi.find('li').eq(index).attr('data_tags'));
				window.location.href = '/regionFeature/toTeshiIndex?rfCode='+oHostList_TeShi.find('li').eq(index).attr('data_tags');
			});

			//列表点击
			mui('#list').on('tap','.mui-indexed-list-item',function(e) {
				// console.log($(this).attr('data-tags'))
				window.location.href = '/regionFeature/toTeshiIndex?rfCode='+$(this).attr('data-tags');
			})

		});
	});


	//设置列表字母头部
	function setGroup(obj,callBack) {
		for(var i = 0; i<myDate.row.length; i++  ) {
			//设置列表字母头部
			oCityListUl.append('<li data-group="' + obj[i].group + '" class="mui-table-view-divider mui-indexed-list-group js_group">' + obj[i].group + '</li>');
			//设置右边导航字母
			oListBar.append('<a>' + obj[i].group + '</a>');
			//设置列表字母对应数据
			setListItem(obj[i],i)
		}
		if(callBack) callBack()
	}

	//设置列表字母对应数据
	function setListItem(obj,index) {
		for(var i=obj.cityNameInfo.length-1; i>-1; i--) {
			oCityListUl.find('.js_group').eq(index).after('<li  data-tags="'+ obj.cityNameInfo[i].tags +'" class="mui-table-view-cell mui-indexed-list-item">'+ obj.cityNameInfo[i].cityName +'</li>')
		}
	}





});